package com.snail.config;

import com.snail.interceptor.GatewayTokenInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Monica
 * @description
 * @date 2025/8/12 17:24
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    // 从配置文件读取网关令牌（与网关的token一致）
    @Value("${gateway.token}")
    private String gatewayToken;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 拦截所有请求（可根据需要调整路径）
        registry.addInterceptor(new GatewayTokenInterceptor(gatewayToken))
                .addPathPatterns("/**")
                .excludePathPatterns("/error");
    }
}